package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.config.TopicConfig;
import com.lkd.contract.SupplyContract;
import com.lkd.contract.TaskCompleteContract;
import com.lkd.emq.Topic;
import com.lkd.exception.LogicException;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: cl
 * @Date: 2022/6/25 - 06 - 25
 * @Description:
 */

//补货工单
@Component
@Topic(TopicConfig.VMS_SUPPLY_TOPIC)
public class SupplyHandler implements MsgHandler {

    //售货机表
    @Autowired
    private VendingMachineService vendingMachineService;

    @Override
    public void process(String jsonMsg) throws IOException {

        if (jsonMsg.isBlank()) throw new LogicException("消息为空");

        //反序列化
        SupplyContract supplyContract = JsonUtil.getByJson(jsonMsg, SupplyContract.class);

        if (supplyContract == null) throw new LogicException("消息反序列化失败！");

        //
        vendingMachineService.supply(supplyContract);

    }
}
